class Solution:
    def splitString(self, s: str, last=None) -> bool:
        if last is None:
            last = []

        if not s and len(last) >= 2:
            return True

        for i in range(1, len(s)):
            now = int(s[:i])
            if last and now != last - 1:
                continue

            last.append(now)
            surplus = s[i:]
            if self.splitString(surplus, last):
                return True
            last.pop()

        print(s, last)
        if last is None:  # 第1个数
            for i in range(1, len(s) - 1):
                num = int(s[:i])
                if self.splitString(s[i:], num):
                    return True
            return False
        elif int(s) < last - 1:  # 最后1个数不符合
            return False
        elif int(s) == last - 1:  # 最后1个数符合
            return True
        else:
            for i in range(1, len(s)):
                num = int(s[:i])
                if num < last - 1 and self.splitString(s[i:], num):
                    return True
            return False


if __name__ == "__main__":
    print(Solution().splitString("1234"))  # False
    print(Solution().splitString("050043"))  # True
    print(Solution().splitString("9080701"))  # False
    print(Solution().splitString("10009998"))  # True
